<template>
	<section>
		<headers txt="银行卡管理"></headers>
		<router-link to="/ownAll/bankadd" class="h_ sz70 hued44">
			+
		</router-link>
		<ul class="p30" v-if="bank">
			<li v-for="(item,index) in bank" class="bank_li wallfff pud30 mu30 rela flex_core flex_column" @click="banktype(index)">
				<span class="bank_f" v-if="item.MembersBank_Mark">默认</span>
				<h1 class=" bbtm flex_core p20">
						<!--<img class="bank_m" :src="item.Image_Url" alt="logo" :onerror='$pub.errImg()' />-->
						
						<strong class="sz30 fontwt ml20">{{item.Bank_Name}}</strong>
					</h1>
				<p class="sz36 pud30">{{item.MembersBank_Account}}</p>
				<p class="sz36">开户行：{{item.MembersBank_Address}}</p>
			</li>
		</ul>
		<p v-else class="centre mu50">没有信息,请点击右上角添加银行卡</p>
		<mt-popup v-model="bankflag" position="bottom" closeOnClickModal="false" class="w100">
			<button type="button" class="bbtm p30 sz36 hued44 centre wallfff w100" @click="defa">设为默认</button>
			<button type="button" class="bbtm p30 sz36 hue666 centre wallfff w100" @click="dele">删除卡号</button>
		</mt-popup>
	</section>
</template>

<script>
	import { Popup } from 'mint-ui';
	import { Toast } from 'mint-ui';
	import { Indicator } from 'mint-ui';
	export default {
		data() {
			return {
				bank: [],
				bankflag: false,
				BankIndex: "",
			}
		},
		created() {
			let v = this;
			if(!sessionStorage.bank) {
				Indicator.open();
				v.$http.get("/WorkMembersAsset/v1.0/GetMembersBank", {
					params: {
						MembersID: sessionStorage.MembersID
					}
				}).then((res) => {
					Indicator.close();
					if(!res.data.Return_ID) {
						let resdata = res.data.Return_Data;
						if(!resdata || !resdata.length) {
							v.bank = null;
							return false;
						}
						v.bank = res.data.Return_Data;
						sessionStorage.bank = JSON.stringify(res.data.Return_Data);
					}
				})
			} else {
				v.bank = JSON.parse(sessionStorage.bank);
			}

		},
		methods: {
			banktype: function(index) {
				this.bankflag = true;
				this.BankIndex = index;
			},
			defa: function() {
				let v = this;
				Indicator.open();
				v.$http.get("/WorkMembersAsset/v1.0/MembersBankSetDefalut", {
					params: {
						MembersBankID: v.bank[v.BankIndex].MembersBank_ID
					}
				}).then((res) => {
					Indicator.close();
					if(!res.data.Return_ID) {
						v.bank.forEach(function(item, index, arr) {
							if(v.BankIndex === index) {
								v.bank[index].MembersBank_Mark = 1;
							} else {
								v.bank[index].MembersBank_Mark = 0;
							}
						})
						sessionStorage.bank = JSON.stringify(v.bank);
					} else {
						Toast(res.data.Return_Mess)
					}
					this.bankflag = false;
				})
			},
			dele: function() {
				let v = this;
				Indicator.open();
				v.$http.get("/WorkMembersAsset/v1.0/MembersBankDel", {
					params: {
						MembersBankID: v.bank[v.BankIndex].MembersBank_ID
					}
				}).then((res) => {
					Indicator.close();
					if(!res.data.Return_ID) {
						v.bank.splice(v.BankIndex, 1);
						if(!v.bank.length) {
							v.bank = null;
							sessionStorage.removeItem('bank');
							this.bankflag = false;
							return;
						}
						sessionStorage.bank = JSON.stringify(v.bank);

					} else {
						Toast(res.data.Return_Mess)
					}
					this.bankflag = false;

				})

			},

		}
	}
</script>

<style>

</style>